package com.mumu.muPictureBackend.model.enums;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户角色枚举:有user admin
 */
@Getter
public enum UserRoleEnum {
    //定义两个枚举: 枚举之前用逗号分隔
    USER("user", 0),
    ADMIN("admin", 2),
    VIP("vip", 1);

    private final String text;
    private final Integer value;

    UserRoleEnum(String text, Integer value) {
        this.text = text;
        this.value = value;
    }


    //加载该类的时候就将所有枚举放到map中 然后查找枚举就可以实现用O(1)的时间复杂度 每次哦
    static final Map<String, UserRoleEnum> map = new HashMap<>();

    static {
        for (UserRoleEnum userRoleEnum : UserRoleEnum.values()) {
            map.put(userRoleEnum.getText(), userRoleEnum);
        }
    }

    //根据枚举值获取枚举
    public static UserRoleEnum getUserRoleEnum(String value) {
        return map.get(value);
    }


}
